package com.zgj.netty_udp.service.impl;

import com.zgj.netty_udp.dao.TempRecordMapper;
import com.zgj.netty_udp.model.TempRecord;
import com.zgj.netty_udp.service.BusinessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;

@Service
public class BusinessServiceImpl implements BusinessService {

    private static final Logger logger = LoggerFactory.getLogger(BusinessServiceImpl.class);

    @Autowired
    private TempRecordMapper tempRecordMapper;

    @Override
    @Async("threadPoolTaskExecutor")
    public void udpHandleMethod(String message) throws Exception {
        logger.info("业务开始处理");
//        Thread.sleep(3000);
        TempRecord tempRecord = new TempRecord();
        tempRecord.setCreateTime(new Timestamp(System.currentTimeMillis()));
        tempRecord.setCrc16(message);
        tempRecordMapper.insert(tempRecord);
        System.out.println(message);
        logger.info("业务处理完成");
    }

}
